#include <bits/stdc++.h>
using namespace std;

char buf[(int)5e7], *fs = buf;

typedef long long ll;

const ll BlueMoonLWZ = (int) 1e9 + 7;

inline ll gn() {
    ll k = 0, f = 1;
    char c = *fs++;
    for (; !isdigit(c); c = *fs++) if (c == '-') f = -1;
    for (; isdigit(c); c = *fs++) k = k * 10 + c - '0';
    return k * f;
}

inline ll md(ll &a) {
    if (a > BlueMoonLWZ) 
        a %= BlueMoonLWZ;
    if (a < 0) 
        (a += BlueMoonLWZ) %= BlueMoonLWZ;
    return a;
}

ll n, m, a[(int)5e4 + 3];

int main() {
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);
    fread(buf, 1, (int)5e7, stdin);
    n = gn(), m = gn();
    for (ll i = 1; i <= n; i++)
        a[i] = gn();        
    for (ll i = 1; i <= m; i++) {
        ll op = gn(), q = gn(), w = gn(), e;
        if (op == 1) { 
            e = gn();
            for (ll i = q; i <= w; i++)
                md(a[i] += e);
        } else if (op == 2) {
            for (ll i = q; i <= w; i++) {
                md(a[i] = -a[i]);
            }
        } else {
            e = gn();
            ll ans = 0;
            if (e == 1) {
                for (int i = q; i <= w; i++)
                    md(ans += a[i]);
            } else if (e == 2) {
                for (int i = q; i <= w; i++) {
                    for (int j = i + 1; j <= w; j++) {
                        md(ans += md(a[i]) * md(a[j]));
                    }
                }
            }
            cout << ans << '\n';
        }
    }
}